package com.richpay.basejava.base10;

public class ObjectToStringDemo {
    public static void main(String[] args) {
        Person p1 = new Person("小丽", 20);

        /**
         *在使用System.out.println();
         * 输出引用数据类型的对象时会自动帮助我们调用toString()方法
         *
         * 在object类中的toString()方法输出的结果为:
         *
         * getClass().getName+"@"+Integer.toHexString(hashCode())
         */
        System.out.println("p1=" + p1);
        System.out.println("p1.toString()=" + p1.toString());


        Worker worker = new Worker("王华", 24);
        System.out.println("worker=" + worker);
        System.out.println("worker.toString()=" + worker.toString());

        System.out.println("worker.getClass().getName=" + worker.getClass().getName());
        System.out.println("worker.hashCode()=" + worker.hashCode());
        System.out.println("Integer.toHexString(hashCode())=" + Integer.toHexString(worker.hashCode()));

        String content = worker.display();//显示调用
        System.out.println("content=" + content);

    }
}
